<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="javax.management.remote.*"%>
<%@ page import="javax.management.*"%>
<%@ page import="com.pica.commons.jmx.*"%>
<%@ page import="java.lang.reflect.*"%>
<%
	String host = request.getParameter("host");
	String port = request.getParameter("port") != null ? request.getParameter("port") : "1099";

	JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/IMConnectorJMXServer");
	try {
		//out.println("Create an connector connect to the IMConnectorJMXServer[" + host + "] ...");
		out.println("<br>");
		JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
		// Get an MBeanServerConnection
		MBeanServerConnection mBeanServerConnection = jmxc.getMBeanServerConnection();

		/*for(String domain : mBeanServerConnection.getDomains()){
			out.println(domain);
			out.println("<br>");
			ObjectName objName = new ObjectName("imconnector:name=");
			ObjectName query = new ObjectName("imconnector:name=*");
		}*/
		for (ObjectInstance oi : mBeanServerConnection.queryMBeans(null, null)) {
			if ("imconnector".equals(oi.getObjectName().getDomain())) {
				out.println("■" + oi.getObjectName() + "    ＃" + oi.getClassName());
				//out.println("-" + oi.getObjectName().getDomain());
				out.println("<br>");
				Object mBean = MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, oi.getObjectName(), Class.forName(oi.getClassName() + "MBean"), false);
				/*for(Field field : mBean.getClass().getDeclaredFields()){
					out.println("  fields list:");
					out.println("  ●"+field.getType()+":"+field.getName()+"="+field.get(mBean));
				}*/
				for (Method method : mBean.getClass().getDeclaredMethods()) {
					try {
						/*out.println("isVarArgs:"+method.isVarArgs());
						out.println("isAccessible:"+method.isAccessible());out.println("<br>");*/
						out.println("  -●" + method.getName() + ":::::::::" + method.invoke(mBean, null));
						out.println("<br>");
					} catch (Exception e) {
					}
				}
			}
		}
		// Call PropertiesUpdate's method
		/*ObjectName objectName = new ObjectName("imconnector:name=" + remoteBeanName);
		Object MBean = MBeanServerInvocationHandler.newProxyInstance(mBeanServerConnection, objectName, clzss, false);
		// MBean方法调用
		MBean.getClass().getMethod(invokeName, types).invoke(MBean, parameters);*/
		//out.println("Destroy the connection of connect to the IMConnectorJMXServer[" + host + "]!");
		jmxc.close();
	} catch (Exception e) {
		//out.println("Call the host[" + host + "] to reload imconnector properties failer!");
		e.printStackTrace();
		out.println(e.getMessage());
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>

		<title>My JSP 'jmx.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>

	<body>
		This is my JSP page.
		<br>
	</body>
</html>
